package com.lagou.scala.test.Q1

class DrinkBeer(money:Int){
  //规则：每瓶啤酒2元，3个空酒瓶或者5个瓶盖可换1瓶啤酒
  var beerPrice = 2//酒价格2元
  var beerCount:Int = money/beerPrice//初始喝酒数
  var capsuleCount:Int = money/beerPrice//初始瓶盖数
  var bottleCount:Int = money/beerPrice//初始酒瓶数
  def drink: Unit = {
    if(capsuleCount>=5){
      var cc:Int = capsuleCount/5
      beerCount = beerCount+cc
      capsuleCount = capsuleCount%5+cc
      bottleCount = bottleCount+cc
    }
    if(bottleCount>=3){
      var cc:Int = bottleCount/3
      beerCount = beerCount+cc
      bottleCount = bottleCount%3+cc
      capsuleCount = capsuleCount+cc
    }
    if(capsuleCount>=5 || bottleCount>=3){
      drink
    }
  }
}
object DrinkBeer {
  def main(args: Array[String]): Unit = {
    val beer = new DrinkBeer(100)
    beer.drink
    println(s"100元最多可喝多少瓶啤酒数：${beer.beerCount}瓶")
  }
}
